package com.edu.exam.enums.assessment;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 严重程度级别枚举
 *
 * <p>定义评估系统中的严重程度级别，用于评估问题、错误、警告等的严重程度。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-17
 */
public enum SeverityLevel implements BaseEnum {

    /**
     * 信息
     */
    INFO("INFO", "信息"),

    /**
     * 调试
     */
    DEBUG("DEBUG", "调试"),

    /**
     * 跟踪
     */
    TRACE("TRACE", "跟踪"),

    /**
     * 通知
     */
    NOTICE("NOTICE", "通知"),

    /**
     * 警告
     */
    WARNING("WARNING", "警告"),

    /**
     * 注意
     */
    ATTENTION("ATTENTION", "注意"),

    /**
     * 严重警告
     */
    SEVERE_WARNING("SEVERE_WARNING", "严重警告"),

    /**
     * 错误
     */
    ERROR("ERROR", "错误"),

    /**
     * 严重错误
     */
    SERIOUS_ERROR("SERIOUS_ERROR", "严重错误"),

    /**
     * 致命错误
     */
    FATAL("FATAL", "致命错误"),

    /**
     * 紧急
     */
    URGENT("URGENT", "紧急"),

    /**
     * 紧急错误
     */
    CRITICAL_ERROR("CRITICAL_ERROR", "紧急错误"),

    /**
     * 灾难性
     */
    CATASTROPHIC("CATASTROPHIC", "灾难性"),

    /**
     * 阻塞性
     */
    BLOCKING("BLOCKING", "阻塞性"),

    /**
     * 关键
     */
    CRITICAL("CRITICAL", "关键"),

    /**
     * 高优先级
     */
    HIGH_PRIORITY("HIGH_PRIORITY", "高优先级"),

    /**
     * 中优先级
     */
    MEDIUM_PRIORITY("MEDIUM_PRIORITY", "中优先级"),

    /**
     * 低优先级
     */
    LOW_PRIORITY("LOW_PRIORITY", "低优先级"),

    /**
     * 最低优先级
     */
    LOWEST_PRIORITY("LOWEST_PRIORITY", "最低优先级"),

    /**
     * 可忽略
     */
    NEGLIGIBLE("NEGLIGIBLE", "可忽略"),

    /**
     * 轻微
     */
    MINOR("MINOR", "轻微"),

    /**
     * 主要
     */
    MAJOR("MAJOR", "主要"),

    /**
     * 重大
     */
    SIGNIFICANT("SIGNIFICANT", "重大"),

    /**
     * 一般
     */
    NORMAL("NORMAL", "一般"),

    /**
     * 标准
     */
    STANDARD("STANDARD", "标准"),

    /**
     * 正常
     */
    REGULAR("REGULAR", "正常"),

    /**
     * 默认
     */
    DEFAULT("DEFAULT", "默认"),

    /**
     * 未知
     */
    UNKNOWN("UNKNOWN", "未知"),

    /**
     * 未分类
     */
    UNCLASSIFIED("UNCLASSIFIED", "未分类"),

    /**
     * 其他
     */
    OTHER("OTHER", "其他");

    private final String code;
    private final String description;

    SeverityLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 获取严重程度数值（用于排序和比较）
     *
     * @return 严重程度数值，值越大越严重
     */
    public int getLevelValue() {
        switch (this) {
            case NEGLIGIBLE: return 0;
            case MINOR: return 1;
            case LOW_PRIORITY:
            case LOWEST_PRIORITY:
            case DEBUG:
            case TRACE: return 2;
            case INFO:
            case NOTICE:
            case NORMAL:
            case STANDARD:
            case REGULAR:
            case DEFAULT:
            case OTHER: return 3;
            case ATTENTION:
            case WARNING: return 4;
            case MEDIUM_PRIORITY: return 5;
            case SEVERE_WARNING:
            case HIGH_PRIORITY: return 6;
            case ERROR:
            case MAJOR: return 7;
            case SERIOUS_ERROR:
            case SIGNIFICANT: return 8;
            case CRITICAL:
            case CRITICAL_ERROR:
            case URGENT:
            case BLOCKING: return 9;
            case FATAL:
            case CATASTROPHIC: return 10;
            case UNKNOWN:
            case UNCLASSIFIED: return -1;
            default: return 3;
        }
    }

    /**
     * 判断是否为错误级别
     *
     * @return 是否为错误级别及以上
     */
    public boolean isError() {
        return this == ERROR || this == SERIOUS_ERROR || this == CRITICAL_ERROR || 
               this == FATAL || this == CATASTROPHIC;
    }

    /**
     * 判断是否为警告级别
     *
     * @return 是否为警告级别
     */
    public boolean isWarning() {
        return this == WARNING || this == ATTENTION || this == SEVERE_WARNING;
    }

    /**
     * 判断是否为信息级别
     *
     * @return 是否为信息级别及以下
     */
    public boolean isInfo() {
        return this == INFO || this == DEBUG || this == TRACE || this == NOTICE;
    }

    /**
     * 判断是否为严重级别
     *
     * @return 是否为严重及以上级别
     */
    public boolean isCritical() {
        return this == CRITICAL || this == CRITICAL_ERROR || this == FATAL || 
               this == CATASTROPHIC || this == URGENT || this == BLOCKING;
    }

    /**
     * 根据编码获取对应的枚举
     *
     * @param code 编码
     * @return 对应的枚举
     */
    public static SeverityLevel fromCode(String code) {
        for (SeverityLevel level : values()) {
            if (level.getCode().equals(code)) {
                return level;
            }
        }
        throw new IllegalArgumentException("Unknown severity level code: " + code);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}
